package com.pmsystem.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pmsystem.pojo.Community;
import com.pmsystem.pojo.CommunityShow;
import com.pmsystem.service.CommunityService;

/**
 * 
* <p>Title: CommunityController</p>  
* <p>Description:处理小区设施信息的控制器</p>  
* @author 树昌  
* @date 2019年1月22日
 */
@Controller
@RequestMapping("Information/")
public class CommunityController {
	
	@Autowired
	CommunityService communityService;
	
	
	/**
	 * 
	 * <p>Title: addCommunity</p>  
	 * <p>Description: </p>  
	 * @author 树昌
	 * @param community
	 * @return 跳转到显示所有小区设施信息的页面
	 */
	@RequestMapping(value="addcommunity",method=RequestMethod.POST)
	public String addCommunity(Community community) {
		
		boolean row = communityService.addCommunity(community);
		if(row) {
			return "Information/showcommunity";
		}else {
			return "error";
		}
	}
	
	
	/**
	 * 
	 * <p>Title: showCommunity</p>  
	 * <p>Description:查询所有的小区设施记录 </p>  
	 * @author 树昌
	 * @return 不做跳转
	 */
	@RequestMapping(value="showcommunity",method=RequestMethod.POST)
	@ResponseBody
	public List<CommunityShow> showCommunity(String keyword, Integer startRow, Integer pageSize,Integer CID){
		
		return communityService.showCommunity(keyword,startRow,pageSize,CID);
	}
	
	
	/**
	 * 
	 * <p>Title: deleteCommunity</p>  
	 * <p>Description:删除一条小区设施的记录 </p>  
	 * @author 树昌
	 * @param community
	 * @return 不做跳转
	 */
	@RequestMapping(value="deletecommunity",method=RequestMethod.POST)
	@ResponseBody
	public void deleteCommunity(Community community) {
		
		communityService.deleteCommunity(community);
	}
	
	
	
	/**
	 * 
	 * <p>Title: updateCommunity</p>  
	 * <p>Description:修改一条小区设施的记录 </p>  
	 * @author 树昌
	 * @param community
	 * @return 跳转到查询所有小区设施信息的页面
	 */
	@RequestMapping(value="updatecommunity",method=RequestMethod.POST)
	public String updateCommunity(Community community) {
		
		boolean row = communityService.updateCommunity(community);
		if(row) {
			return "Information/showcommunity";
		}else {
			return "error";
		}
	}
}
